package com.sizu.web;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sizu.common.vo.ResultEntity;
import com.sizu.entity.TMenu;
import com.sizu.entity.TRole;
import com.sizu.entity.TRoleMenu;
import com.sizu.service.ITMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.List;

/**
 *
 * @author 高旌洋
 * @since 2020-02-24
 */
@RestController
@RequestMapping("/user/menu")
@Slf4j
public class TMenuController {


    @Resource
    ITMenuService menuService;
    @RequestMapping("/getMenuByUserName")
    public ResultEntity getMenuByUserName(Principal member){
        log.info("當前登錄用戶的信息為:{}", JSON.toJSONString(member));
//        UsernamePasswordAuthenticationToken u = (UsernamePasswordAuthenticationToken) member;
//        //log.info(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
        //TODO:admin 死數據
        log.info("用户名是：",member.getName());
        List<TMenu> menus = menuService.getMenuByUserName(member.getName());
        return ResultEntity.ok(menus);
    }

    /**
     * 根据条件获取menu
     * @param tMenu
     * @return
     */
    @RequestMapping("/list")
    public ResultEntity getMenuList(TMenu tMenu){
        Wrapper<TMenu> wrapper=new EntityWrapper<>(tMenu);
        List<TMenu> tMenus = menuService.selectList(wrapper);
        return ResultEntity.ok("查询成功",tMenus);
    }

    @RequestMapping("/getRoleMenuById")
    public ResultEntity getRoleMenu(Integer id){
        log.info("id------>{}",id);
        List<String> roleMenuById = menuService.getRoleMenuById(id);
        log.info("roleMenuById------>{}",roleMenuById);
        return ResultEntity.ok(roleMenuById);
    }

    @RequestMapping("/getRoleMenu")
    public ResultEntity getRoleMenu(){
        List<TMenu> roleMenu = menuService.getRoleMenu();
        return ResultEntity.ok(roleMenu);
    }

}
